package cn.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * @author yexi
 */
@RestController
@RequestMapping("test")
@Api(tags = {"这是测试用的接口"})
public class DemoController {

    @ApiOperation(value = "测试接口", notes = "相关描述")
    // swagger2生成测试接口时的解释和生成逻辑
    @ApiImplicitParam(name = "params", value = "对该参数想添加的介绍，一般介绍参数是什么", paramType = "body", required = true, dataType = "object")
    @PostMapping("/demo")
    public HashMap<String, Object> demo(@RequestBody Map<String, Object> params) {
        System.out.println(params);
        HashMap<String, Object> result = new HashMap<>();
        result.put("参数1", "值1");
        result.put("参数2", "值2");
        return result;
    }


    @ApiOperation(value = "测试接口2", notes = "相关描述2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id:id", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "name", value = "name:名称", required = true, dataType = "string", paramType = "query")
    })
    @PostMapping("/demo2/{id}")
    public HashMap<String, Object> demo2(String name, @PathVariable("id") Long id) {
        System.out.println("名称: " + name + " id: " + id);
        HashMap<String, Object> result = new HashMap<>();
        result.put("参数1", "值1");
        result.put("参数2", "值2");
        return result;
    }

}
